Skip to content

Conversation

@Yasindu20
Copy link

Summary

Adds support for specifying which Chrome profile to use via a new --profile-directory CLI option.

Motivation

Users often need to:

  • Test with different browser profiles that have specific extensions installed
  • Maintain separate contexts for different projects
  • Use profiles with pre-configured settings or logged-in accounts

Currently, there's no way to specify which profile Chrome should use when launched by the MCP server.

Changes

  • ✅ Added --profile-directory CLI option with kebab-case alias
  • ✅ Updated BrowserOptions interface to include profileDirectory property
  • ✅ Connected CLI argument to Chrome's --profile-directory launch flag
  • ✅ Added documentation in README.md with usage examples
  • ✅ Included in the auto-generated options documentation

Usage Example

{
  "mcpServers": {
    "chrome-devtools": {
      "command": "npx",
      "args": [
        "chrome-devtools-mcp@latest",
        "--profile-directory=Profile 1"
      ]
    }
  }
}

Or via command line:

npx chrome-devtools-mcp --profile-directory="Profile 1"
  • Documentation generated correctly with npm run docs
  • format with npm run format

Related Issues

Fixes #694

Added a new CLI option to allow users to specify which Chrome profile
to use when launching the browser.

Changes:
- Added --profile-directory CLI argument
- Updated BrowserOptions interface
- Connected CLI arg to Chrome launch flag
- Added documentation in README.md
@OrKoN OrKoN requested a review from sebastianbenz January 12, 2026 08:52
Copy link
Collaborator

@sebastianbenz sebastianbenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, one suggestion on the docs.

@sebastianbenz
Copy link
Collaborator

Did you test this with autoconnect? I just tested this by running Chrome in "Profile 1" and setting "--profile-directory=Profile 2". In this case, the MCP server still connected to Profile 1, but I would've expected the connection to fail. Or is this the intended behavior?

@Yasindu20
Copy link
Author

Did you test this with autoconnect? I just tested this by running Chrome in "Profile 1" and setting "--profile-directory=Profile 2". In this case, the MCP server still connected to Profile 1, but I would've expected the connection to fail. Or is this the intended behavior?

@sebastianbenz Yes, I tested this with autoconnect and saw the same behavior even when Chrome is running with “Profile 1”, the MCP server still connects successfully when --profile-directory=Profile 2 is specified. So, I add a validation step to detect a profile mismatch after connecting and fail fast instead of silently attaching to the wrong profile. The intention is to avoid surprising connections when a specific profile is explicitly requested. Let me know if you’d like me to add anything specific to the docs around the profile behavior.

@tacsizkral546154
Copy link

tacsizkral546154 commented Jan 13, 2026 via email

src/browser.ts Outdated

if (options.profileDirectory && options.userDataDir) {
try {
const portPath = path.join(options.userDataDir, 'DevToolsActivatePort');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

such file does not exist, did you mean DevToolsPort. A single user data dir hosts multiple profiles so I am not sure if the check handles it correctly.

src/browser.ts Outdated
);
}

if (options.profileDirectory && options.userDataDir) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think this check should be in the connection code branch.

default: true,
describe: 'Set to false to exclude tools related to network.',
},
profileDirectory: {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we probably should be using https://pptr.dev/api/puppeteer.browser.browsercontexts to locate the browser context for the profile (currently the default browser context is used)

… the connection path, switched to referencing browser.browserContexts()
@Yasindu20
Copy link
Author

@OrKoN I fixed the DevToolsActivePort from DevToolsActivatePort. Removed the profile validation logic since a single userDataDir can contain multiple profiles, and that check isn’t reliable. Also removed the profile-related checks from the connection path, add it to the function launch(). For profile handling, I switched to referencing browser.browserContexts() and added clear logging that we currently fall back to the default context. Proper profile → context mapping can be improved once Puppeteer exposes a cleaner way to do this.

logger(`Found ${contexts.length} browser context(s)`);

logger(
`Profile directory "${profileDirectory}" specified. ` +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this PR does not add anything useful without the implementation for finding the browser context that matches the profileDirectory name. Passing --profile-directory to Chrome is already possible via the --chrome-arg param. Would you be up to figuring out how to find the correct browser context? it might right changes on the CDP and Puppeteer side.

@Yasindu20
Copy link
Author

@OrKoN Puppeteer or CDP don’t currently expose profile directory info for browser contexts. Now I tried to implement it to open a temporary page in each context, reads chrome://version to get the profile path, and matches it to the requested --profile-directory. If no match is found, it falls back to the default context. This works with existing APIs and can be updated later if CDP/Puppeteer expose profile metadata. If need any changes let me know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support multiple Chrome Profiles

4 participants